//
//  NSOutlineViewExtension.swift
//  JKTools
//
//  Created by 姜奎 on 2/25/25.
//


import Cocoa

extension NSOutlineView {

    func isItemSelected(_ item: Any) -> Bool {
        selectedRowIndexes.contains(row(forItem: item))
    }

    var selectedItem: Any? {
        item(atRow: selectedRow)
    }

    var selectedItems: [Any] {
        selectedRowIndexes.compactMap {item(atRow: $0)}
    }

    func selectItems(_ items: [Any]) {
        selectRows(items.map {row(forItem: $0)})
    }
}
